import { getCurrentLoginInfo } from '@/api/session'
import abp from 'abp'

const state = {
  tenant: null,
  tenantId: null,
  user: null,
  userId: null
}

const mutations = {
  SET_TENANT: (state, tenant) => {
    state.tenant = tenant
    state.tenantId = state.tenant ? state.tenant.id : null
  },
  SET_USER: (state, user) => {
    state.user = user
    state.userId = user ? user.id : null
  }
}

const actions = {
  init({ commit }) {
    return new Promise((resolve, reject) => {
      resolve()
      // getCurrentLoginInfo().then(data => {        
      //   if (!data || !data.user) {          
      //     reject('Verification failed, please Login again.')
      //   }
      //   const { tenant, user } = data

      //   commit('SET_TENANT', tenant)
      //   commit('SET_USER', user)
      //   resolve(data)
      // }).catch(error => {
      //   reject(error)
      // })
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
